package org.tinygroup.template.anltr.parser;

import java.io.OutputStreamWriter;
import java.io.Writer;

import org.tinygroup.template.TemplateContext;
import org.tinygroup.template.TemplateEngine;
import org.tinygroup.template.impl.TemplateContextDefault;
import org.tinygroup.template.interpret.TemplateInterpretEngine;
import org.tinygroup.template.loader.FileObjectResourceLoader;

import junit.framework.TestCase;

/**
 * 
 * @author Young
 *
 */
@SuppressWarnings("static-access")
public class TinyTemplateAnltrParse extends TestCase {
  public void test_render_set() throws Exception {
    TemplateInterpretEngine engine = new TemplateInterpretEngine();
    TemplateContext context = new TemplateContextDefault();
    Writer writer = new OutputStreamWriter(System.out);
    engine.interpreter.interpret(null, null, "#set(abc=123)  ${abc} #eol   ##123", "abc", context,
        writer);
  }

  public void test_render_for_break() throws Exception {
    TemplateInterpretEngine engine = new TemplateInterpretEngine();
    TemplateContext context = new TemplateContextDefault();
    Writer writer = new OutputStreamWriter(System.out);
    engine.interpreter.interpret(null, null, "#for(i: [1,2,3,4,5])  ${i}   #break(i>3)   #end",
        "abc", context, writer);

    FileObjectResourceLoader tinySample =
        new FileObjectResourceLoader("vm", "layout", null, "src/test/resources");
    engine.addResourceLoader(tinySample);
    engine.renderTemplate("/template/tiny/for-break.vm");
  }


  public void test_render_for_map() throws Exception {
    TemplateInterpretEngine engine = new TemplateInterpretEngine();
    TemplateContext context = new TemplateContextDefault();
    Writer writer = new OutputStreamWriter(System.out);
    engine.interpreter.interpret(null, null,
        "#set ( map = {123: 1, 456: 2}) #for (x : map)  ${x.value} #end", "abc", context, writer);
  }

  public void test_render_for_continue() throws Exception {
    TemplateEngine engine = new TemplateInterpretEngine();
    FileObjectResourceLoader tinySample =
        new FileObjectResourceLoader("vm", "layout", null, "src/test/resources");
    engine.addResourceLoader(tinySample);
    engine.renderTemplate("/template/tiny/for-continue.vm");
  }
  public void test_render_stop() throws Exception {
    TemplateInterpretEngine engine = new TemplateInterpretEngine();
    TemplateContext context = new TemplateContextDefault();
    Writer writer = new OutputStreamWriter(System.out);
    engine.interpreter.interpret(null, null, "1234567890 #stop 111", "abc", context, writer);
  }
}
